function relativeTime(pastTime)
{
    var origStamp = Date.parse(pastTime);var curDate = new Date();var currentStamp = curDate.getTime();var difference = parseInt((currentStamp - origStamp)/1000);
    if(difference < 0) return false;if(difference <= 5)return "Just now";if(difference <= 20)return "Seconds ago";if(difference <= 60)return "A minute ago";if(difference < 3600)return parseInt(difference/60)+" minutes ago";if(difference <= 1.5*3600)return "One hour ago";if(difference < 23.5*3600)return Math.round(difference/3600)+" hours ago";if(difference < 1.5*24*3600)return "One day ago";
    var dateArr = pastTime.split(' ');return dateArr[4].replace(/\:\d+$/,'')+' '+dateArr[2]+' '+dateArr[1]+(dateArr[3]!=curDate.getFullYear()?' '+dateArr[3]:'');
}

function tweetBox() {
	var randomnumber=Math.floor(Math.random()*11);  

	document.write( '<div id="' + randomnumber +'"></div>');

	this.create = function(user,hashtag,tweetAmount) {
		        var twurl = "http://search.twitter.com/search.json?rpp="+tweetAmount+"&q=from%3A" + user + "+" + escape(hashtag) + "&callback=?";

			jQuery.ajax({
  			url: twurl,
  			dataType: 'jsonp',
			success: function(data) {

				thisdiv = jQuery('#' + randomnumber);
				thisdiv.addClass('tweetHolder');					
				thistitle = jQuery(document.createElement('h3'));
				thistitle.text('Reviews - Latest T3 Tweets');
				thistitle.addClass('rlTitle');
				tweetdiv = jQuery(document.createElement('div'));
				tweetdiv.addClass('tweet');					
				jQuery.each(data.results, function(i, item) {
					tweetdiv.append( '<div>' + ify.clean(item.text) + '<span style="float:right;"><b>' +  relativeTime(item.created_at)  + '</b></span><div class="clear"></div></div>' );	
				});	
									
				thisdiv.append( thistitle );
				thisdiv.append( tweetdiv );
				thisdiv.append('<a href="http://www.twitter.com/t3dotcom" class="tweetLink"><img src="http://twitter-badges.s3.amazonaws.com/follow_us-b.png" alt="Follow t3dotcom on Twitter"/></a><div style="clear:both;"></div>');

  			},
			error: function(req, Status, error) {
				alert( Status + error );			
			}
		});
	}
};